package com.zjc.app.api.sdk.utils;

import java.sql.Timestamp;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

    public static Timestamp getCurrentTime() {
        Date date1 = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = sdf.format(date1);
        Timestamp timestamp = Timestamp.valueOf(str);
        return timestamp;
    }

    public static String getCurrentTimeStr() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static String getCurrentTimeStr(String pattern) {
        return new SimpleDateFormat(pattern).format(new Date());
    }

    public static String dateCoverterToStr(Date date) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }

    public static Date strConverterToDate(String str) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(str, pos);
        return strtodate;
    }

    public static String beforeDay(Date now, Integer days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date dBefore = calendar.getTime();
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dBefore);
    }

    public static Timestamp beforeDayTime(Date now, Integer days) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date dBefore = calendar.getTime();
        return new Timestamp(dBefore.getTime());
    }
}
